public with sharing class AssetProjectNewController {

    //资产项目对象 视图使用放大镜的时候会使用到
    public AssetProject__c ap{get;set;}
    //仪器id
    public String eId{get;set;}
    public String dataJson {get;set;}

    public String calibratorCombox {get;set;}
    public String qualityProductsCombox {get;set;}
    public String reagentSupplierCombox {get;set;}
    public String singlePackageDimensionCombox {get;set;}
    public String isJoinQualityEvaluationCombox {get;set;}


    public AssetProjectNewController() {
        
        ap = new AssetProject__c();
        eId = System.currentPageReference().getParameters().get('eid');

    }

    public void init(){
    	getData();
    	getCombox();
    }
    public void getCombox(){
    	calibratorCombox = getOptMap(ImportObject.getPicklistValues('AssetProject__c', 'Calibrator__c', false));
    	qualityProductsCombox = getOptMap(ImportObject.getPicklistValues('AssetProject__c', 'QualityProducts__c', false));
    	reagentSupplierCombox = getOptMap(ImportObject.getPicklistValues('AssetProject__c', 'ReagentSupplier__c', false));
    	singlePackageDimensionCombox = getOptMap(ImportObject.getPicklistValues('AssetProject__c', 'SinglePackageDimension__c', false));
    	isJoinQualityEvaluationCombox = getOptMap(ImportObject.getPicklistValues('AssetProject__c', 'IsJoinQualityEvaluation__c', false));
    }
    public void getData(){
    	List<AssetBean> tmp = new List<AssetBean>();
    	Set<Id> existSet = new Set<Id>();
    	for(AssetProject__c ap:[select Id ,Name ,ProductProject__c , Brand__c,Brand__r.Name , IndoorQualityControlBrand__r.Name , 
    		Supplier__r.Name , Supplier__c,SinglePackageDimension__c,SinglePackagePrice__c,ReagentSupplier__c,IsJoinQualityEvaluation__c,
    		QualityProducts__c,Calibrator__c,Account__c,IndoorQualityControlBrand__c,SampleAmount__c
    			from AssetProject__c where Instrument__c =:eId
    		]){
    		existSet.add(ap.ProductProject__c);
    		tmp.add(new AssetBean(ap));
    	}


    	/* List<Equipment__c> eqList=[select Name,Product__r.Category1__c,Product__r.Category2__c,Supplier__c,Supplier__r.Name,Account__c from Equipment__c where Id=:eId];
        if(eqList.size()>0){
            Equipment__c eq=eqList[0];
            Product__c product=eq.Product__r;//获得产品
            
            String [] arr = product.Category2__c.split('-',2);
            String category2='%'+arr[0]+'-%';

           	for(ProductProject__c pp:[select Name,Id from ProductProject__c where (ThirdClassification__c='试剂' or ThirdClassification__c='试纸') 
                                            and PrimaryClassification__c=:product.Category1__c
                                            and SecondClassification__c like :category2]){

           		if(!existSet.contains(pp.Id)){

           			tmp.add(new AssetBean(pp,eq));
           		}

           	}
             
          
        }*/
        dataJson = EncodingUtil.urlEncode(JSON.serialize(tmp),'UTF-8');
    }

    public String getOptMap(Map<String,String> opts){
      
       Map<String ,Object> cooMap = new Map<String ,Object> ();
      cooMap.put('valueField', 'value');
      cooMap.put('textField', 'label');
      cooMap.put('panelHeight', 'auto');
      cooMap.put('limitToList', 'true');
      List<Map<String,String>>  dList = new List<Map<String,String>>();
      for (String k : opts.keySet()) {
        Map<String ,String> dataMap = new Map<String,String>();
        dataMap.put('label',opts.get(k) );
        dataMap.put('value',k );
        dList.add(dataMap);
      }  
      cooMap.put('data', dList);   
      
      return EncodingUtil.urlEncode(JSON.serialize(cooMap), 'UTF-8');
    }
    public class AssetBean{

    	public string name ;//项目名称
    	public string projectId ;//项目id
    	public string projectbrand ;//项目品牌名称
    	public string projectbrandId ;//项目品牌Id
    	public String indoorbrand;//室间品牌名称
    	public String indoorbrandId ;//室间品牌ID

    	public String supplier ;//供应商
    	public String supplierId ;//供应商ID
    	public String spec ;//单包装规格
    	public String price ;//单包装价格
    	public String reagentsupplier;// 试剂供应方
    	public String isevaluate;//是否参加室间质评
    	public String isfreeq;//质控品是否赠送
    	public String isfreeCalibrator;//校准品是否赠送
    	public String accId;
    	public String daynum ;//日标本量

    	public Boolean isSeleted;



    	public AssetBean(AssetProject__c ap){

    		name = ap.Name;
    		projectId = ap.ProductProject__c;

    		projectbrandId = ap.Brand__c;
    		projectbrand = ap.Brand__r.Name;

    		indoorbrand = ap.IndoorQualityControlBrand__r.Name;
    		indoorbrandId = ap.IndoorQualityControlBrand__c;

    		supplier = ap.Supplier__r.Name;
    		supplierId = ap.Supplier__c;
    		accId = ap.Account__c;

    		spec = ap.SinglePackageDimension__c;
    		price = String.valueOf(ap.SinglePackagePrice__c);

    		reagentsupplier = ap.ReagentSupplier__c;
    		isevaluate = ap.IsJoinQualityEvaluation__c;
    		isfreeq = ap.QualityProducts__c;
    		isfreeCalibrator = ap.Calibrator__c;
    		daynum = String.valueOf(ap.SampleAmount__c );
    		isSeleted = true;

    	}
    	public AssetBean(ProductProject__c pp,Equipment__c e ){
    		name = pp.Name;
    		projectId = pp.Id;
    		supplier = e.Supplier__r.Name;
    		supplierId = e.Supplier__c;
    		accId = e.Account__c;
    		isSeleted = false;
    	}	


    }
}